%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% APPENDIX: COMPUTE THE TOTAL DEMAND FOR DEFORESTATION AND PLOT THE CURVES
% COMPARE 'FIXED-PROPORTIONS' AND 'VERTICAL' MODELS

% "DEFORESTATION IN THE AMAZON:
% A UNIFIED FRAMEWORK FOR ESTIMATION AND POLICY ANALYSIS"

% by Eduardo Souza-Rodrigues

% This version: November 2018

% OBSERVATIONS: 
% Run this program after running "dem_def_reg.m" & "dem_def_compute_demand.m"

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% (A) COMPUTE TOTAL DEMAND

% I. Prepare the Data    

% Load Demand (calculated in "dem_def_compute_demand.m")
% Demand_farm_jc = [transfer' tot_demand_iv' tot_demand_ivqr'] 
% Demand - Crops & Pasture
load Demand_farm_1cp;
load Demand_farm_2cp;
load Demand_farm_3cp;
load Demand_farm_4cp;

% Demand - Only Crops
load Demand_farm_1c;
load Demand_farm_2c;
load Demand_farm_3c;
load Demand_farm_4c;

% II. Define Variables

% Transfers/Taxes 
transfer_c   = Demand_farm_1c(:,1);
transfer_cp  = Demand_farm_1cp(:,1);

% Demand for Deforestation - Crops & Pasture Index ('Fixed-proportions' model)
demand_def_cp1 = Demand_farm_1cp(:,3);
demand_def_cp2 = Demand_farm_2cp(:,3);
demand_def_cp3 = Demand_farm_3cp(:,3);
demand_def_cp4 = Demand_farm_4cp(:,3);
demand_def_cp  = demand_def_cp1 + demand_def_cp2 + demand_def_cp3 + demand_def_cp4;

% Demand for Deforestation - Only Crops Index ('vertical' model)
demand_def_c1 = Demand_farm_1c(:,3);
demand_def_c2 = Demand_farm_2c(:,3);
demand_def_c3 = Demand_farm_3c(:,3);
demand_def_c4 = Demand_farm_4c(:,3);
demand_def_c  = demand_def_c1 + demand_def_c2 + demand_def_c3 + demand_def_c4;


%% (B) PLOT DEMAND CURVES

% Compare 'Fixed-Proportions' vs 'Vertical Models (Crops & Pasture vs Only Crops)
demand_def_prodindex_fig = figure;
plot(demand_def_c/1000000,transfer_c,'r-',demand_def_cp/1000000,transfer_cp,'b--*')
xlabel('Agricultural Area (Million hectares)','fontsize',15)
ylabel('Taxes (US$/ha)','fontsize',15)
title('"Fixed-Proportions" Model vs. "Vertical" Model','fontsize',17)
axis([-3 50 0 200])
h_legend=legend('"Vertical" Model','"Fixed-Proportions" Model');
set(h_legend,'FontSize',13);
saveas(demand_def_prodindex_fig,'DemDef-ProdIndex.png')


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
